<?php

namespace app\index\controller;

use app\common\controller\Front;

/**
 * 前台 - 首页
 * Class Index
 * @package app\index\controller
 */
class Index extends Front
{
    /**
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index()
    {

        $place_id = $this->isMobile() ? 2 : 1;
        $ads = model('Ad')->field('title,cover_id,url')->where(['place_id' => $place_id, 'status' => 1])->order('id DESC')->select();
        $this->assign('ads', $ads);

        $notice = model('Article')
            ->field('id,title,create_time')
            ->where(['status' => 1, 'category_id' => 8])
            ->order('id DESC')
            ->limit(10)
            ->select();

        $this->assign('notice', $notice);

        $borrows = model('Borrow')
            ->field('*')
            ->where(['is_publish' => 1])
            ->order('id DESC')
            ->limit(8)
            ->select();

        $this->assign('borrows', $borrows);

//        $this->assign('news', model('Article')->field('id,title,create_time')->where(['category_id' => 1])->order('id DESC')->select());
//        $this->assign('company', model('Article')->field('id,title,create_time')->where(['category_id' => 2])->order('id DESC')->select());
//        $this->assign('media', model('Article')->field('id,title,create_time')->where(['category_id' => 3])->order('id DESC')->select());

        return $this->fetch();
    }
}
